home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 376-400 / disk_376 / toollibrary / src / intui3.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  11KB  |  342 lines

  1.  /********************************************************************/
  2.  /****                                                            ****/
  3.  /****                                                            ****/
  4.  /****    Program          : Intui-Funktionen                     ****/
  5.  /****                                                            ****/
  6.  /****    Version          :    01.07                             ****/
  7.  /****                                                            ****/
  8.  /****    Erstversion      : 21.05.1988                           ****/
  9.  /****                                                            ****/
  10.  /****    Letzte Änderung  : 01.06.1990                           ****/
  11.  /****                                                            ****/
  12.  /****    Compiliert mit   : siehe MAKE                           ****/
  13.  /****                                                            ****/
  14.  /****    Gelinkt mit      : Für Tool.Library                     ****/
  15.  /****                                                            ****/
  16.  /********************************************************************/
  17.  /****                                                            ****/
  18.  /****                                                            ****/
  19.  /****               Copyright by Rüdiger Dreier                  ****/
  20.  /****                                                            ****/
  21.  /****                                                            ****/
  22.  /********************************************************************/
  23.  
  24.  #include "ToolProto.h"
  25.  #include <intuition/intuition.h>
  26.  #include <intuition/intuitionbase.h>
  27.  #include <libraries/dos.h>
  28.  #include <graphics/gfxmacros.h>
  29.  #include <exec/memory.h>
  30.  #include <intuition/intuitionbase.h>
  31.  #include <proto/intuition.h>
  32.  #include <proto/graphics.h>
  33.  #include <stdlib.h>
  34.  #include <stdio.h>
  35.  #include <string.h>
  36.  
  37.  
  38.  #define ACTIVE_SCREEN IntuitionBase->ActiveScreen
  39.  #define ACTIVE_WINDOW IntuitionBase->ActiveWindow
  40.  #define CODE  ((Message!=0) ? Message->Code  : 0)
  41.  #define CLASS ((Message!=0) ? Message->Class : 0)
  42.  #define CircleFill(RP,x,y,r) EllFill(RP,x,y,r,r);
  43.  
  44.  extern struct IntuitionBase *IntuitionBase;
  45.  extern struct GfxBase       *GfxBase;
  46.  
  47.  /* Zeichnet einen Kasten.. */
  48.  VOID __asm Box(register __a1 struct RastPort *RastPort,    /* Der RastPort */
  49.                 register __d0 LONG xs,                      /* Start: X     */
  50.                 register __d1 LONG ys,                      /* Start: Y     */
  51.                 register __d2 LONG xe,                      /* Ende : X     */
  52.                 register __d3 LONG ye)                      /* Ende : Y     */
  53.   {
  54.    Move(RastPort,xs,ys);
  55.    Draw(RastPort,xe,ys);
  56.    Draw(RastPort,xe,ye);
  57.    Draw(RastPort,xs,ye);
  58.    Draw(RastPort,xs,ys);
  59.   }
  60.  
  61.  
  62.  /* Gibt eine Text zentriert im Fenster aus */
  63.  VOID __asm Center(register __a1 struct Window *Window,     /* Das Fenster  */
  64.                    register __a0 char *string,              /* Der Text     */
  65.                    register __d0 LONG Color,                /* Die Farbe    */
  66.                    register __d1 LONG y_Pos)                /* Die Y-Pos.   */
  67.   {
  68.    LONG x;
  69.    x=((LONG)Window->Width-strlen(string)*8)/2;
  70.    Print(Window->RPort,string,Color,x,y_Pos);
  71.   }
  72.  
  73.  /* Schaltet ein Gadget ein (ENABLE) */
  74.  VOID __asm Gadget_On(register __a0 struct Gadget *Gadget,  /* Das Gadget   */
  75.                       register __a1 struct Window *Window)  /* Das Fenster  */
  76.   {
  77.    BYTE APen;
  78.    
  79.    if (Gadget->Flags & GADGDISABLED)
  80.     {
  81.      APen=Window->RPort->FgPen;
  82.      SetAPen(Window->RPort, 0L) ;
  83.     /* Zeichenbereich löschen */
  84.      RectFill(Window->RPort,(long)Gadget->LeftEdge,
  85.               (long)Gadget->TopEdge,
  86.               (long)Gadget->LeftEdge+Gadget->Width-1,
  87.               (long)Gadget->TopEdge+Gadget->Height-1);
  88.      SetAPen(Window->RPort, (LONG)APen) ;
  89.     /* Gadget neu zeichnen */
  90.      OnGadget(Gadget, Window, NULL) ;
  91.     }
  92.   }
  93.  
  94.  
  95.  /* Schaltet ein Gadget aus (DISABLE) */
  96.  VOID __asm Gadget_Off(register __a0 struct Gadget *Gadget, /* Das Gadget   */
  97.                        register __a1 struct Window *Window) /* Das Fenster  */
  98.   {
  99.    if (!(Gadget->Flags & GADGDISABLED))
  100.     {
  101.      OffGadget(Gadget, Window, NULL);
  102.     }
  103.   }
  104.  
  105.  
  106.  
  107.  /* Holt horizontale Position des PropGadgets */
  108.  LONG __asm GetPropPosH(register __a0 struct Gadget *Gadget,/* Das Gadget   */
  109.                         register __d0 LONG MaxPos)          /* Max. Pos.    */
  110.   {
  111.    struct PropInfo *PInfo;
  112.    long Pos;
  113.    
  114.    PInfo=(struct PropInfo *)Gadget->SpecialInfo;
  115.    if(MaxPos&&PInfo)
  116.     {
  117.      Pos=(PInfo->HorizPot)*MaxPos/MAXBODY;
  118.      if(Pos==MaxPos)
  119.       {
  120.        Pos--;
  121.       }
  122.      return(Pos);
  123.     }
  124.    else
  125.     {
  126.      return(0);
  127.     }
  128.   }
  129.  
  130.  /* Holt vertikale Position des PropGadgets */
  131.  LONG __asm GetPropPosV(register __a0 struct Gadget *Gadget,/* Das Gadget   */
  132.                         register __d0 LONG MaxPos)          /* Max. Pos.    */
  133.   {
  134.    struct PropInfo *PInfo;
  135.    long Pos;
  136.    
  137.    PInfo=(struct PropInfo *)Gadget->SpecialInfo;
  138.    if(MaxPos&&PInfo)
  139.     {
  140.      Pos=(PInfo->VertPot)*MaxPos/MAXBODY;
  141.      if(Pos==MaxPos)
  142.       {
  143.        Pos--;
  144.       }
  145.      return(Pos);
  146.     }
  147.    else
  148.     {
  149.      return(0);
  150.     }
  151.   }
  152.  
  153. /* Die beiden folgenden Routinen verändern ..Pot und ..Body entsprechend */
  154. /* den übergebenen Werten. Schrittweite ist für ..Body und MaxPos/NewPos */
  155. /* für ..Pot verantwortlich. Bsp: Es soll ein Bereich mit 15 Zeilen ge-  */
  156. /* scrollt werden, wobei je 5 Zeilen gleichzeitig angezeigt werden können*/
  157. /* MaxPos ist somit 11 (von Zeile 0 bis 10 kann jede als oberste der 5   */
  158. /* auftauchen). Schrittweite ist 3 (Z0-4, Z5-9 und Z10-14 können jeweils */
  159. /* angezeigt werden). NewPos gibt dann die aktuelle Position an (z.B. 9) */
  160. /* Klick der Anwender dann NEBEN den Schieberegler, so spring der um     */
  161. /* max. Schrittweite weiter, d.h. aus Position 9 wird z.B. 4. Da hier mit*/
  162. /* Ganzzahlen gerechnet wird, gibt es manchmal Probleme, wenn der An-    */
  163. /* wender den Regler selbst verschoben hat. Hat er den Regler z.B. so    */
  164. /* verschoben, daß die Position gerade noch als 9 erkannt wird (und noch */
  165. /* nicht als 8), dann kann es passieren, daß durch Anklicken neben dem   */
  166. /* Regler als nächste Position 3 und nicht 4 angegeben wird.             */
  167.  
  168.  
  169.  
  170.  /* Setzt PropGadget auf horizontalen Wert */
  171.  VOID __asm SetPropPosH(register __a0 struct Gadget *Gadget,/* Das Gadget   */
  172.                         register __a1 struct Window *Window,/* Das Fenster  */
  173.                         register __d0 LONG MaxPos,          /* Die MaxPos   */
  174.                         register __d1 LONG Schrittweite,    /* Schrittweite */
  175.                         register __d2 LONG NewPos)          /* Neue Posit.  */
  176.   {
  177.    struct PropInfo *PInfo;
  178.    LONG Position;
  179.    
  180.    PInfo=(struct PropInfo *)Gadget->SpecialInfo;
  181.    if(MaxPos)
  182.     {
  183.      if(MaxPos>1)
  184.       {
  185.        Position=MAXBODY*NewPos/(MaxPos-1);
  186.       }
  187.      else
  188.       {
  189.        Position=MAXBODY;
  190.       }
  191.      if(Position>=MAXBODY)
  192.       {
  193.        Position=MAXBODY;
  194.       }
  195.      ModifyProp(Gadget,
  196.                 Window,
  197.                 NULL,
  198.                 PInfo->Flags,
  199.                 Position,
  200.                 PInfo->VertPot,
  201.                 (MAXBODY/Schrittweite),
  202.                 PInfo->VertBody);
  203.     }
  204.   }
  205.  
  206.  
  207.  
  208.  /* Setzt PropGadget auf vertikalen Wert */
  209.  VOID __asm SetPropPosV(register __a0 struct Gadget *Gadget,/* Das Gadget   */
  210.                         register __a1 struct Window *Window,/* Das Fenster  */
  211.                         register __d0 LONG MaxPos,          /* Die MaxPos   */
  212.                         register __d1 LONG Schrittweite,    /* Schrittweite */
  213.                         register __d2 LONG NewPos)           /* Neue Posit.  */
  214.   {
  215.    struct PropInfo *PInfo;
  216.    LONG Position;
  217.    
  218.    PInfo=(struct PropInfo *)Gadget->SpecialInfo;
  219.    if(MaxPos)
  220.     {
  221.      if(MaxPos>1)
  222.       {
  223.        Position=MAXBODY*NewPos/(MaxPos-1);
  224.       }
  225.      else
  226.       {
  227.        Position=MAXBODY;
  228.       }
  229.      if(Position>=MAXBODY)
  230.       {
  231.        Position=MAXBODY;
  232.       }
  233.      ModifyProp(Gadget,
  234.                 Window,
  235.                 NULL,
  236.                 PInfo->Flags,
  237.                 PInfo->HorizPot,
  238.                 Position,
  239.                 PInfo->HorizBody,
  240.                 (MAXBODY/Schrittweite));
  241.     }
  242.   }
  243.  
  244. /* Diese Funktion bereitet alles vor, damit die Flood-Funktion */
  245. /* benutzt werden kann.                                        */
  246.  LONG __asm PrepareTmpRas(register __a1 struct RastPort *RP)/* Der RastPort */
  247.   {
  248.    struct TmpRas   *Ras;
  249.    struct BitMap   *BitMap;
  250.    LONG Breite,Hoehe;
  251.    BYTE *Plane;
  252.    
  253.    BitMap=RP->BitMap; /* BitMap des RastPorts */
  254.    
  255. /* Berechnen von Breite und Höhe (stimmt nicht unbedingt */
  256. /* mit Werten des Windows überein, besonders nicht bei   */
  257. /* SuperBitMaps. Auch bei Fensterbreiten wie 630 wird    */
  258. /* 640 errechnet. RASSIZE berechnet aber aus beiden      */
  259. /* das gleiche Ergebnis (immer ganze Worte)              */
  260.    Breite=BitMap->BytesPerRow*8;
  261.    Hoehe =BitMap->Rows;
  262.    
  263.    if(RP->TmpRas)return(0); /* Schon ein TmpRas */
  264.    
  265.    Plane=AllocRaster(Breite,Hoehe); /* Speicher für Plane */
  266.    if(!Plane)return(0);
  267.    
  268. /* Speicher für Struktur holen */
  269.    Ras=AllocMem(sizeof(struct TmpRas),MEMF_CLEAR);
  270.    if(!Ras)
  271.     {
  272.      FreeRaster(Plane,Breite,Hoehe);
  273.      return(0);
  274.     }
  275.    
  276. /* Struktur initialisieren */
  277.    InitTmpRas(Ras,Plane,RASSIZE(Breite,Hoehe));
  278.    
  279.    RP->TmpRas=Ras; /* RastPort mitteilen */
  280.    
  281.    return((LONG)Ras); /* Wert ungleich NULL */
  282.   }
  283.  
  284. /* Die Funktion gibt den belegten Speicher wieder frei */
  285.  VOID __asm ClearTmpRas(register __a1 struct RastPort *RP)   /* Der RastPort */
  286.   {
  287.    struct TmpRas *TRas;
  288.    struct BitMap *BitMap;
  289.    BYTE *Plane;
  290.    
  291.    TRas=RP->TmpRas;   /* Zeiger auf Struktur  */
  292.    BitMap=RP->BitMap; /* Die BitMap           */
  293.    
  294.    RP->TmpRas=NULL;   /* Verknüpfung aufheben */
  295.    Plane=TRas->RasPtr;/* Zeiger auf BitPlane  */
  296.    
  297. /* Beide Speicherbereiche freigeben */
  298.    FreeRaster(Plane,BitMap->BytesPerRow*8,BitMap->Rows);
  299.    FreeMem(TRas,sizeof(struct TmpRas));
  300.   }
  301.  
  302.  LONG __asm PrepareArea(register __a1 struct RastPort *RP,
  303.                         register __d0 LONG MaxPoints)
  304.   {
  305.    UWORD *Liste;
  306.    struct AreaInfo *AI;
  307.    Liste=0;
  308.    if(PrepareTmpRas(RP))
  309.     {
  310.          
  311.      AI=(struct AreaInfo *)AllocMem(sizeof(struct AreaInfo),MEMF_CLEAR);
  312.      if(!AI)
  313.       {
  314.        ClearTmpRas(RP);
  315.        return(0);
  316.       }
  317.      
  318.      Liste=AllocMem(MaxPoints*5,MEMF_CLEAR);
  319.      if(!Liste)
  320.       {
  321.        FreeMem(AI,sizeof(struct AreaInfo));
  322.        ClearTmpRas(RP);
  323.        return(0);
  324.       }
  325.      InitArea(AI,Liste,MaxPoints);
  326.      RP->AreaInfo=AI;
  327.     }
  328.    return((LONG)Liste);
  329.   }
  330.  
  331.  VOID __asm ClearArea(register __a1 struct RastPort *RP)
  332.   {
  333.    struct AreaInfo *AI;
  334.    if(AI=RP->AreaInfo)
  335.     {
  336.      FreeMem(AI->VctrTbl,AI->MaxCount*5);
  337.      FreeMem(AI,sizeof(struct AreaInfo));
  338.     }
  339.    ClearTmpRas(RP);
  340.   }
  341.  
  342.